package com.sdkx.app.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RadioGroup;

import com.sdkx.app.R;
import com.sdkx.app.adapter.MainMenuAdapter;

public class MapFragment extends BaseFragment {
    //航线管理二级目录
    private String[] CourseList = {"图层管理", "绘图管理"};
    private ListView lvGroup;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_menu_map1, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        lvGroup = (ListView) view.findViewById(R.id.mapmenulist);
        MainMenuAdapter menuadapter = new MainMenuAdapter(getActivity(), CourseList);
        lvGroup.setAdapter(menuadapter);
        lvGroup.setOnItemClickListener(new MenuAdapterViewListener());
        //返回上一级点击事件
        Button tv_all_air_spaces = (Button) view.findViewById(R.id.tv_all_air_spaces2);
        //返回上一级按钮
        tv_all_air_spaces.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goBack();
            }
        });
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });
        RadioGroup group = view.findViewById(R.id.radiogroup);
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.radio_svg:
                        break;
                    case R.id.radio_photo:
                        break;
                }
            }
        });

    }

    //二级菜单点击事件
    private class MenuAdapterViewListener implements AdapterView.OnItemClickListener {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // ((MainActivity)getActivity()).ShowMainMenu(position+71); //显示对应的二级菜单
            Class<? extends Fragment> obj = null;
            switch (position) {
                case 0:
                    obj = MapLayerFragment.class;
                    break;
                case 1:
                    obj = DrawMapFragment.class;
                    break;
            }
            startFragment(obj);
        }
    }

}